package com.juzipi.thread.test;

/**
 * @Author juzipi
 * @Date 2021/6/15 15:46
 * @Info
 */
public class StaticProxy {

    public static void main(String[] args) {
        //静态代理模式
        Weddind weddind = new Weddind(new Person());
        weddind.eat();
        //Runnable就是静态代理模式吧
        new Thread(()-> System.out.println("年后")).start();

    }

}

interface Marry{

    void eat();

    void sleep();

    void learn();

    void play();

}

class Person implements Marry{

    private final String name = "张三";

    @Override
    public void eat() {
        System.out.println(name+"要吃饭");
    }

    @Override
    public void sleep() {
        System.out.println(name+"要睡觉");
    }

    @Override
    public void learn() {
        System.out.println(name+"要学习");
    }

    @Override
    public void play() {
        System.out.println(name+"要玩");
    }
}
//代理对象，实现同一个接口
class Weddind implements Marry{

    private Marry marry;

    public Weddind(Marry marry){
        this.marry = marry;
    }


    @Override
    public void eat() {
        before();
        this.marry.eat();//真实对象
        after();
    }

    private void after(){
        System.out.println("收拾收拾");
    }

    private void before(){
        System.out.println("准备吃的");
    }


    @Override
    public void sleep() {
        this.marry.sleep();
    }

    @Override
    public void learn() {
        this.marry.learn();
    }

    @Override
    public void play() {
        this.marry.play();
    }
}